package com.interview.ujiuye;

import java.util.concurrent.TimeUnit;

class MyData{
    public synchronized void save(){
        System.out.println("==========开始执行添加操作========");
        try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); }
        System.out.println("save");
        System.out.println("==========结束执行添加操作========");
    }
    //字节码对象 MyData.class
    public static synchronized void delete(){
        System.out.println("==========开始执行删除操作========");
        System.out.println("delete");
        System.out.println("==========结束执行删除操作========");
    }
}


public class Demo4 {
    public static void main(String[] args) {
        MyData myData = new MyData();
        new Thread(){
            @Override
            public void run() {
                myData.save();
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                myData.delete();
            }
        }.start();
    }
}
